#!/usr/bin/python
# -*- mode:python; coding:utf-8 -*-

import cv

c = cv.CreateCameraCapture(0)

cv.NamedWindow("Test 02")
cv.StartWindowThread()

dst = None
while True:
    src = cv.QueryFrame(c)
    if not src: break

    # Create destination frame (same size as source, 8 bits, 1 channel)
    if dst is None:
        dst = cv.CreateImage((src.width, src.height), cv.IPL_DEPTH_8U, 1)

    # Convert from RGB to GRAY scale
    cv.CvtColor(src, dst, cv.CV_RGB2GRAY)

    cv.ShowImage("Test 02", dst)
    d = 1000 / 20
    k = cv.WaitKey(d)
    if k != -1: break

